﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Drawing;


namespace Projektkylsim
{
    class Ventil
    {
        private Nod n;
        private double admittans= 10;
        private double ventil_position=1.0;
        private string namn;
        private double rityta;
        private Nod innod, utnod;
        private double x, y;
        private double flode;
        public int X { get; set; }
        public int Y { get; set; }
        
        private Graphics canvas;
        
        public Ventil(Nod inn, Nod ut, int x, int y)
        {
            innod = inn;
            utnod = ut;
            this.x = X;
            this.y = Y;
        }


        

        public void rita(Graphics canvas)
        {
            Pen pen = new Pen(Color.Black);
            Brush brush = new SolidBrush(Color.Black);
            Font font = new Font("Courier", 12);
            String s = "Flöde:" + String.Format("{0:F2}", flode);
            canvas.DrawString(s, font, brush, X, Y);
            canvas.DrawString(s, font, brush, 400, Y);
            //canvas.DrawString("Flöde:" + string.Format("{0:F1}", flode), font, brush, 150, 385);
            //canvas.DrawString("Flöde:" + string.Format("{0:F1}", flode), font, brush, 400, 385);

            Point point1 = new Point(150, 380);
            Point point2 = new Point(150, 340);
            Point point3 = new Point(210, 380);
            Point point4 = new Point(210, 340);
           

            Point[] punkt =
            {
                point1,
                point2,
                point3,
                point4,


            };
            Point punkt1 = new Point(400, 380);
            Point punkt2 = new Point(400, 340);
            Point punkt3 = new Point(450, 380);
            Point punkt4 = new Point(450, 340);
            Point[] punkt5 =
            {
                punkt1,
                punkt2,
                punkt3,
                punkt4,


            };

            canvas.DrawPolygon(pen, punkt);
            canvas.DrawPolygon(pen, punkt5);

          
        }
        public void oppna() 
        {

        }
        public void stang() 
        { 
        }
        public void dynamik(Nod n) 
        {
            
            double p = this.innod.Tryck - this.utnod.Tryck;
            if (flode >= 0)
                flode = admittans * ventil_position * Math.Sqrt(p);
            else if (flode <= 0)
                flode = -admittans * ventil_position * Math.Sqrt(p);
            n.add_summaflode(flode);
        }
    }
}
